{extend name="layout/main" /}

{block name="header"}

{/block}

{block name="content"}
<style type="text/css">
    .link-th{
        color:blue;
    }
</style>
<section class="panel">
    <header class="panel-heading">
        <h4>会员列表</h4>
    </header>
    <div class="panel-body" style="padding-bottom: 50px">
        <form class="form-horizontal" action="">
            <div class="form-group">
                <div class="col-xs-1 no-pd-r">
                    <select name="type" id="type" class="form-control">
                        <option {if $Request.get.type == 'sn_id'} selected {/if} value="sn_id">机器编码</option>
                        <option {if $Request.get.type == 'mobile'} selected {/if} value="mobile">绑定的会员账号</option>
                        <option {if $Request.get.type == 'p_mobile'} selected {/if} value="p_mobile">会员名下</option>
                    </select>
                </div>
                <div class="col-xs-3 no-pd-l">
                    <input type="text" id="keyword" value="{$Request.get.keyword}" name="keyword" class="form-control" placeholder="请输入关键词搜索">
                </div>
                <!--<div class="col-xs-3 no-pd-l">
                    <input type="number" value="{$Request.get.page}" name="page" class="form-control" placeholder="请输入页码">
                </div>-->
                <button type="submit" class="btn btn-color">搜索</button>
            </div>
        </form>
        <form class="form-horizontal" action="{:url('addSn')}" enctype="multipart/form-data" method="post">
            <div class="form-group" style="padding-left: 15px">
                <div class="col-xs-3 no-pd-l">
                    <input type="file" name="excel" class="form-control" >
                </div>
                <button  type="submit" class="btn btn-info">导入</button>
            </div>
        </form>
        <table class="table table-bordered table-striped no-margin">
            <thead>
            <tr>
                <th class="text-center">ID</th>
                <th class="text-center">机器编号</th>
                <th class="text-center">导入时间</th>
                <th class="text-center">绑定会员</th>
                <th class="text-center">是否绑定</th>
                <th class="text-center">绑定时间</th>
                <th class="text-center">会员名下</th>
                <th class="text-center">操作</th>
            </tr>
            </thead>
            <tbody>
            {if !empty($list)}
                {foreach $list as $entity}
                <tr>
                    <td style="vertical-align: middle" class="text-center">
                        {$entity.id}
                    </td>
                    <td style="vertical-align: middle" class="">
                        {$entity.sn_id}

                    </td>
                    <td style="vertical-align: middle" class="text-center">
                        {:date('Y-m-d H:i:s',$entity.create_time)}
                    </td>

                    <td style="vertical-align: middle" class="text-center">
                        {$entity.mobile}
                    </td>
                    <td style="vertical-align: middle" class="text-center">
                        {if $entity.is_bind == 1}
                        已绑定
                        {else}
                        未绑定
                        {/if}
                    </td>
                    <td style="vertical-align: middle" class="text-center">
                        {if $entity.is_bind == 1}
                        {:date('Y-m-d H:i:s',$entity.bind_time)}
                        {else}

                        {/if}
                    </td>
                    <td>
                        {if isset($entity.account_pos.mobile)}
                        {$entity.account_pos.mobile}
                        {else}
                        暂无绑定
                        {/if}
                    </td>
                    <td style="vertical-align: middle" class="text-center">
                        {if isset($entity.account_pos.mobile)}
                        <button class="btn btn-xs btn-danger" onclick="unbindNext({$entity.id})">解绑会员名下</button>
                        {else}
                        <button class="btn btn-xs btn-primary" onclick="bindNext({$entity.id})">绑定会员名下</button>
                        {/if}




                        {if $entity.is_bind != 1}
                        <button class="btn btn-xs btn-primary" onclick="bind({$entity.id})">绑定会员</button>
                        {else}
                        <button class="btn btn-xs btn-danger" onclick="unbind({$entity.id})">解绑</button>
                        {/if}
                    </td>
                </tr>
                {/foreach}
            {else /}
            <tr class="text-center">
                <td colspan="9">暂无数据</td>
            </tr>
            {/if}
            </tbody>
        </table>
        <div class="page">
            {:htmlspecialchars_decode($list->render())}
        </div>
    </div>
</section>
{/block}
{block name="footer"}
<script>

    function bindNext(id){
        var mobile=prompt("请输入用户手机");
        if (mobile!=null && mobile!=""){
            $.post('{:url("bindNext")}',{id:id,mobile:mobile},function(res){
                if(res.code == 0){
                    window.location.reload();
                }else{
                    alert(res.message)
                }
            })
        }
    }
    function unbindNext(id){
        if(window.confirm('确定要解绑吗？')) {
            $.post('{:url("unbindNext")}', {id: id}, function (res) {
                if (res.code == 0) {
                    window.location.reload();
                } else {
                    alert(res.message)
                }
            })
        }
    }

    function bind(id){
        var mobile=prompt("请输入用户手机");
        if (mobile!=null && mobile!=""){
            $.post('{:url("bindSnId")}',{id:id,mobile:mobile},function(res){
                if(res.code == 0){
                    window.location.reload();
                }else{
                    alert(res.message)
                }
            })
        }
    }
    function unbind(id){

        if(window.confirm('确定要解绑吗？')) {
            $.post('{:url("unbindSnId")}', {id: id}, function (res) {
                if (res.code == 0) {
                    window.location.reload();
                } else {
                    alert(res.message)
                }
            })
        }
    }
</script>

{/block}
